package com.web.controller;

import com.github.pagehelper.PageInfo;
import com.web.entity.HealthAssessment;
import com.web.entity.Result;
import com.web.service.HealthAssessmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/assess")
@CrossOrigin
public class HealthAssessmentController {
    @Autowired
    private HealthAssessmentService healthAssessmentService;

    //http://localhost:8080/assess/list?page=1&pageSize=5
    @GetMapping("/list")
    public Result list(Integer page, Integer pageSize, HealthAssessment healthAssessment){
        PageInfo<HealthAssessment> list = this.healthAssessmentService.list(page, pageSize, healthAssessment);
        return Result.success(list);
    }

    //http://localhost:8080/assess/findById?assessmentId=1
    @GetMapping("/findById")
    public Result findById(Integer assessmentId){
        HealthAssessment healthAssessment = this.healthAssessmentService.findById(assessmentId);
        return Result.success(healthAssessment);
    }

    //http://localhost:8080/assess/add
    @PostMapping("/add")
    public Result add(@RequestBody HealthAssessment healthAssessment){
        this.healthAssessmentService.add(healthAssessment);
        return Result.success();
    }

    //http://localhost:8080/assess/update
    @PutMapping("/update")
    public Result update(@RequestBody HealthAssessment healthAssessment){
        this.healthAssessmentService.update(healthAssessment);
        return Result.success();
    }

    //http://localhost:8080/assess/delete/1
    @DeleteMapping("/delete/{assessmentId}")
    public Result delete(@PathVariable Integer assessmentId){
        this.healthAssessmentService.delete(assessmentId);
        return Result.success();
    }

    //http://localhost:8080/assess/findUserId?userId=1
    @GetMapping("/findUserId")
    public Result byUserId(Integer userId){
        List<HealthAssessment> healthAssessments = this.healthAssessmentService.byUserId(userId);
        return Result.success(healthAssessments);
    }

    //http://localhost:8080/assess/byDoctorId?doctorId=1
    @GetMapping("/findDoctorId")
    public Result byDoctorId(Integer doctorId){
        HealthAssessment healthAssessment = this.healthAssessmentService.byDoctorId(doctorId);
        return Result.success(healthAssessment);
    }









}
